Skip to content

fix: Deprecated strlen(null) in Redis Hashtable on PHP 8.1+#44

Merged
ralflang merged 2 commits intohorde:FRAMEWORK_6_0from
jcdelepine:FRAMEWORK_6_0
Mar 7, 2026
Merged

fix: Deprecated strlen(null) in Redis Hashtable on PHP 8.1+#44
ralflang merged 2 commits intohorde:FRAMEWORK_6_0from
jcdelepine:FRAMEWORK_6_0

Conversation

@jcdelepine
Copy link
Contributor

Problem

On PHP 8.1+, calling strlen(null) raises a deprecation warning in Redis Hashtable configuration when no password is set.

Solution

Replaced strlen() check with !empty() to ensure proper handling of null/empty passwords while preserving previous behavior.

Compatibility

  • No change in functionality.
  • Tested on PHP 8.4

### Problem
On PHP 8.1+, calling `strlen(null)` raises a deprecation warning in Redis Hashtable configuration when no password is set.

### Solution
Replaced `strlen()` check with `!empty()` to ensure proper handling of null/empty passwords while preserving previous behavior.

### Compatibility
- No change in functionality.
- Tested on PHP 8.4

$common = array_filter([
'password' => strlen($params['password']) ? $params['password'] : null,
'password' => !empty($params['password']) ? $params['password'] : null,
Copy link
Contributor

@amulet1 amulet1 Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to try null coalescing for cases with possibly missing string parameters:
$value ?? $value_if_missing_or_null

For example:
'password' => $params['password'] ?? null

One caveat is that if $params['password'] is set to empty string, it would not change it to null.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, one of the issues with empty() is that it returns true for '0' (or 0).

Since we are modifying this file, it makes sense to improve things.

Address review: use null coalescing operator
@ralflang
Copy link
Member

ralflang commented Mar 7, 2026

Thank you, much appreciated!

@ralflang ralflang merged commit bf2a3e9 into horde:FRAMEWORK_6_0 Mar 7, 2026
4 checks passed
@ralflang
Copy link
Member

ralflang commented Mar 7, 2026

@amulet1 Please make a follow-up PR with your suggested next improvement as time permits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants